package com.zack.multithread.tool;
/**
* author: dejian
* 2017  Sep 1, 2017  11:48:14 PM  (could be changed)
**/

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.poi.ss.formula.functions.T;
/**
* author: dejian
* 2017  Sep 2, 2017  12:27:27 AM  (could be changed)
* 下面最好用静态方法做。 
**/
public class MultiThreadPool<V> {
    private  ConcurrentLinkedQueue<V> queus = new ConcurrentLinkedQueue<>();
    private CountDownLatch countDownLatch = new CountDownLatch(10);
    ExecutorService exeService = null;

    public MultiThreadPool(int nThreads) {
        initThreadPool(nThreads);
    }

    private void initThreadPool(int nThreads) {
        exeService = Executors.newFixedThreadPool(nThreads);
    }

    public void runThreads() {
        for (;;) {
            SingleThread<Integer> singleThread = new SingleThread<>(countDownLatch);
            exeService.submit(singleThread);
            break;
        }
        try {
            countDownLatch.await();
        } catch (Exception e) {
            System.out.println("error: "+e);
        }
        System.out.println("上面执行完才会执行这里。");
    }
}
